
package com.zsrt.day20170506.socket;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

/**
 * 接收端
 * @author jmj
 * @date 2017年5月6日
 * @time 下午4:57:43
 */
public class UDPSocket {

	public static void main(String[] args) throws Exception {
		
		DatagramSocket ds = new DatagramSocket(4321);
		
		while(true){
			byte[] data = new byte[1024];
			DatagramPacket dp = new DatagramPacket(data, data.length );
			
			ds.receive(dp);
			
			String str = new String(dp.getData(), 0, dp.getLength());
			
			System.out.println(str);
		}
		
	}
}
